CREATE OR REPLACE TRIGGER %TRIGGER_NAME%
AFTER %TRIGGER_EVENTS% ON %TABLE_NAME% 
FOR EACH ROW
DECLARE
    xml        clob;
    new_values xmltype;
    old_values xmltype;
    operation  char(1);
BEGIN
    IF INSERTING OR UPDATING THEN
        xml := '<row tableName="%TABLE_NAME%" xmlns="http://www.matasek.net/DatabaseLogger" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
        
        %LOGGING_TRIGGER_LOOP_NEW%  
        
        xml := xml || '</row>';
        
        new_values := xmltype(xml);
    ELSE
        new_values := NULL;
    END IF;


    IF DELETING OR UPDATING THEN
        xml := '<row tableName="%TABLE_NAME%" xmlns="http://www.matasek.net/DatabaseLogger" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
        
        %LOGGING_TRIGGER_LOOP_OLD%  
        
        xml := xml || '</row>';
        
        old_values := xmltype(xml);
    ELSE
        old_values := NULL;
    END IF;


    IF INSERTING THEN
        operation  := 'I';
    ELSIF UPDATING THEN
        operation := 'U';     
    ELSIF DELETING THEN
        operation := 'D';     
    END IF;

    
    INSERT INTO
        %LOGGING_TABLE_NAME% (id, table_name, operation, old_values, new_values)
    VALUES
        (%SEQUENCE_NAME%.nextval, '%TABLE_NAME%', operation, old_values, new_values);
END;
